package com.example.tool.ck;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.context.annotation.Primary;
import org.springframework.jdbc.core.JdbcTemplate;
import ru.yandex.clickhouse.ClickHouseDriver;

import javax.sql.DataSource;

/**
 * @className: ClickhouseConfig
 * @Auther: charlie
 * @Date: 2022/12/9 11:47
 * @Description:
 */

public class ClickhouseConfig {
    private String driverClassName= ClickHouseDriver.class.getCanonicalName();
    private String url="online.ck.url";
    private String username="online.ck.username";
    private String password="online.ck.password";
    private Integer initialSize=1;
    private Integer minIdle =1;
    private Integer maxActive=1;
    private Integer maxWait=1;
    private String validationQuery="select 1";


    @Primary
    public DataSource clickhouseDataSource(){
        DruidDataSource ck = new DruidDataSource();
        ck.setDbType(driverClassName);
       // ck.setDriverClassName(driverClassName);
        ck.setUrl(url);
        ck.setUsername(username);
        ck.setPassword(password);
        ck.setInitialSize(initialSize);
        ck.setMinIdle(minIdle);
        ck.setMaxActive(maxActive);
        ck.setMaxWait(maxWait);
        ck.setValidationQuery(validationQuery);
        return ck;
    }



    @Primary
    public  JdbcTemplate clickhouseTemplate(){
        JdbcTemplate ck = new JdbcTemplate(clickhouseDataSource());
        ck.setResultsMapCaseInsensitive(true);
        return ck;
    }
}
